#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/*Acrossthe         wecanreacheverycornerintheworld GreatWall,
5
10 18 ery cor
32 40 , we
1 6 tW all
14 18 rnerr eache
1 1 e r
*/
void ctrlx(char* str)
{
	int x, y, i;
	scanf("%d%d", &x, &y);
	char str1[6];
	char str2[6];
	scanf("%s%s", str1, str2);
	i = y - x;
	char* p = str;
	int len = strlen(str);
	int z = x;
	while (--z)
		p++;
	
	char* copy = (char*)malloc(sizeof(char) * (i + 2));
	strncpy(copy, p, i + 1);
	copy[i + 1] = '\0';
	char* p3 = str + y;
	int j = 0;
	while (p3[j] != '\0')
	{
		str[x + j-1] = p3[j];
		j++;
	}
	str[x + j] = '\0';
	char* p1 = strstr(str, str1);
	char* p2 = strstr(str, str2);
	j = 0;
	int len1 = strlen(copy);

	while (p2[j] != '\0')
	{
		p2[j + i + 1] = p2[j];
		j++;
	}
	p2 = p2 - 1;
	
	j = 0;
	for (j = 0; j < len1; j++)
	{
		p2[j] = copy[j];
	}
}
int main()
{
	int n = 0;
	char str[201] = { 0 };
	gets(str);
	scanf("%d", &n);
	while (n--)
	{
		ctrlx(str);
		printf("%s\n", str);
	}

	return 0;
}